$(function(){
    $("#loginform :input").click(function(){
        $(this).css("border-color","#6bb4ff");
    });
    $("#loginform :input").focus(function(){
        $(this).css("border-color","#6bb4ff");
    });
    $("#loginform :input").blur(function(){
        $(this).css("border-color","#e2e2e2");
    });
	
    Tab();
    LoginBind();
    init();
    GetDateString();
    GetcDateString();

})

function Tab(){
    var beforTab = $("#hot li:first-child");
    $("#hot li").mouseover(function(){
        if(beforTab){
            var tabcontent = beforTab.attr("tabcontent");
            beforTab.removeClass("on");
            $("#"+tabcontent).css("display","none");
        }
        var $li = $(this);
        beforTab=$li;
        var tabcontent = beforTab.attr("tabcontent");
        $("#"+tabcontent).css("display","block");
        $li.addClass("on");
		
    });
}

function LoginBind(){
    $("#loginBtn").click(function(){
        var verificationCode = $("#verificationCode").val();
        var password = $("#password").val();
        var username = $("#username").val();
        
    });
}


var CalendarData=new Array(20); 
var madd=new Array(12); 
var TheDate=new Date(); 
var tgString="甲乙丙丁戊己庚辛壬癸"; 
var dzString="子丑寅卯辰巳午未申酉戌亥"; 
var numString="一二三四五六七八九十"; 
var monString="正二三四五六七八九十冬腊"; 
var weekString="日一二三四五六"; 
var sx="鼠牛虎兔龙蛇马羊猴鸡狗猪"; 
var cYear; 
var cMonth; 
var cDay; 
var cHour; 
var cDateString; 
var DateString; 
var Browser=navigator.appName;
 
 
function init() {
    CalendarData[0] = 0x41A95;
    CalendarData[1] = 0xD4A;
    CalendarData[2] = 0xDA5;
    CalendarData[3] = 0x20B55;
    CalendarData[4] = 0x56A;
    CalendarData[5] = 0x7155B;
    CalendarData[6] = 0x25D;
    CalendarData[7] = 0x92D;
    CalendarData[8] = 0x5192B;
    CalendarData[9] = 0xA95;
    CalendarData[10] = 0xB4A;
    CalendarData[11] = 0x416AA;
    CalendarData[12] = 0xAD5;
    CalendarData[13] = 0x90AB5;
    CalendarData[14] = 0x4BA;
    CalendarData[15] = 0xA5B;
    CalendarData[16] = 0x60A57;
    CalendarData[17] = 0x52B;
    CalendarData[18] = 0xA93;
    CalendarData[19] = 0x40E95;
    madd[0] = 0;
    madd[1] = 31;
    madd[2] = 59;
    madd[3] = 90;
    madd[4] = 120;
    madd[5] = 151;
    madd[6] = 181;
    madd[7] = 212;
    madd[8] = 243;
    madd[9] = 273;
    madd[10] = 304;
    madd[11] = 334;
}
 
 
function GetBit(m, n) {
    return (m >> n) & 1;
}
 
 
function e2c() {
    var total, m, n, k;
    var isEnd = false;
    TheDate=new Date();
    var tmp = TheDate.getYear();
    if (tmp < 1900) tmp += 1900;
    total = (tmp - 2001) * 365
    + Math.floor((tmp - 2001) / 4)
    + madd[TheDate.getMonth()]
    + TheDate.getDate()
    - 23;
    if (TheDate.getYear() % 4 == 0 && TheDate.getMonth() > 1)
        total++;
    for (m = 0; ; m++) {
        k = (CalendarData[m] < 0xfff) ? 11 : 12;
        for (n = k; n >= 0; n--) {
            if (total <= 29 + GetBit(CalendarData[m], n)) {
                isEnd = true;
                break;
            }
            total = total - 29 - GetBit(CalendarData[m], n);
        }
        if (isEnd) break;
    }
    cYear = 2001 + m;
    cMonth = k - n + 1;
    cDay = total;
    if (k == 12) {
        if (cMonth == Math.floor(CalendarData[m] / 0x10000) + 1)
            cMonth = 1 - cMonth;
        if (cMonth > Math.floor(CalendarData[m] / 0x10000) + 1)
            cMonth--;
    }
    cHour = Math.floor((TheDate.getHours() + 3) / 2);
}
 
 
function GetcDateString() {
    e2c();
    var tmp = "";
    tmp += tgString.charAt((cYear - 4) % 10);   //年干 
    tmp += dzString.charAt((cYear - 4) % 12);   //年支 
    tmp += "年(";
    tmp += sx.charAt((cYear - 4) % 12);
    tmp += ")";
    if (cMonth < 1) {
        tmp += "闰";
        tmp += monString.charAt(-cMonth - 1);
    }
    else
        tmp += monString.charAt(cMonth - 1);
    tmp += "月";
    tmp += (cDay < 11) ? "初" : ((cDay < 20) ? "十" : ((cDay < 30) ? "廿" : "卅"));
    if (cDay % 10 != 0 || cDay == 10)
        tmp += numString.charAt((cDay - 1) % 10);
    if (cHour == 13) tmp += "夜";
    tmp += dzString.charAt((cHour - 1) % 12);
    tmp += "时";
    $("#chinese_date").html(tmp);
    setTimeout("GetDateString()",60000);
}
 
 
function GetDateString() {
    var date = "";
    TheDate=new Date();
    var t1 = TheDate.getYear();
    if (t1 < 1900) t1 += 1900;
    date += t1+"年"+(TheDate.getMonth() + 1) + "月"+ TheDate.getDate()+"日";
    $("#date").html(date);
		
    var time = "";
    var hour=TheDate.getHours();
    time+=hour + ":"+ ((TheDate.getMinutes() < 10) ? "0" : "")+ TheDate.getMinutes();
    $("#time").html(time);
    var week = "";
    week+= " 星期" + weekString.charAt(TheDate.getDay());
	
    $("#week").html(week);
	
    var pic = "";
    if(hour>=6 && hour<=12){
        pic="morning_ico";
    }else if(hour>12 && hour<=18){
        pic="noon_ico";
    }else if(hour>18 || hour<6){
        pic="evening_ico";
    }
	
    var time_pic = $("#time_pic");
    time_pic.removeClass();
    time_pic.addClass(pic);
	
    setTimeout("GetDateString()",60000);
}

function bindRegedit(url,fromurl){
    $("#regeditBtn").click(function(){
        var height = window.screen.availHeight;
        var width = window.screen.availWidth;
        $("body").append("<div id=\"shraw\" class=\"opacity\" style=\"background:gray;position:absolute;left:0; top:0;width:"+width+"px;height:"+height+"px\"></div>");
        //                alert(url);
        $("#regeditDiv").load(url,"",function(data){
            var s = $("#regeditDiv");
            s.css("left",width/2-250);
            s.css("top",height/2-240);
            initRegeitPanel(fromurl);
        });
    });

}
//初始化注册
function initRegeitPanel(fromurl){
    //确定按钮
    $("#submit_regeit").click(function(){
        var sel = checkRegedit();
        if(sel){
            var username = $("#username").val();
            var psd = $("#psd").val();
            var psd2 = $("#psd2").val();
            var email = $("#email").val();
            $.post(fromurl,
            {
                username: username,
                psd: psd,
                email:email
            },
            function(data){
//                alert(data);
                if(data == 1){
                    alert('注册成功，请登录')
                    close();
                }
                else if(data == 3){
                    alert('用户名已被注册')
                }
                else{
                    alert('注册失败')
                }
            }
            );
           
        }
    });
    $("#cancel_regeit").click(close);
    function checkRegedit(){
        var resulte = true;
        var username = $("#username");
        var psd = $("#psd");
        var psd2 = $("#psd2");
        var emial = $("#email");
        if (username.val() == "") {
            username.next().text("*请填写用户名");
            resulte=false;
        }else
        {
            username.next().empty();
        }
        if (psd.val() == "") {
            psd.next().text("*请填写密码");
            resulte=false;
        }else
        {
            psd.next().empty();
        }
        if (psd2.val() == "") {
            psd2.next().text("*请再次填写密码");
            resulte=false;
        }else if(psd2.val()!==psd.val()){
            psd2.next().text("*二次密码错误");
            resulte=false;
        }else
        {
            psd2.next().empty();
        }

        if (emial.val() == "") {
            emial.next().text("*请填写您的邮箱");resulte=false;
        }else
        {
            emial.next().empty();
        }

        return resulte;


    }

    function close(){
        $("#regeditDiv").empty();
        $("#submit_regeit").unbind();
        $("#cancel_regeit").unbind();
        $("body").get(0).removeChild($("#shraw").get(0));
    }
}

 
 

